<template>
  <div >
    <enum_chb :param="{}" v-if="enumField_pattr.enum_val&&enumField_pattr.fval!==undefined" :field="enumField_pattr" @setVo='setEnum' ></enum_chb>
    <div v-if="notHave" class="ui message info">
      <p>该商品的规格都已经绑定到该仓库</p>
    </div>
  </div>

  <!--<enum_many :param="{}" v-if="enumField_pattr.enum_val&&enumField_pattr.fval!==undefined" :field="enumField_pattr" type="checkbox" @setVo='setEnum' ></enum_many>-->
</template>

<script type="text/ecmascript-6">
  import tool from 'src/util/tool';
  import util from '_util/index';
  import logic from '_logic';

  import enum_chb from 'components/field/enum_chb';
  import enum_many from 'components/field/enum_many';

  export default {
    data() {
      return {
        pattr: '',
        notHave: false,

        enumField_pattr:{
          name:'pattr',
          title:'',
          enum_val:null
        },
      }
    },
    components: {enum_chb,enum_many},
    methods: {
      getProductAttr(){
        let url = tool.getApi(this, 'Editget', 'getProductAttrs');
        let param =  util.store.get(this, 'editVoModal');
        util.getDataCom(this, url, param, (rs) => {
          rs=rs.attr_names;
          if(rs&&Object.keys(rs).length>0) {
            let tmp = [];
            for(let ind in rs) {
              tmp.push({
                id: ind,
                title: rs[ind]
              })
            }
            this.$set(this.enumField_pattr, 'enum_val', tmp);
            this.$set(this.enumField_pattr, 'fval', '');
          }else{
//            util.showMsg(this, 'info', '该商品的规格都已经绑定到该仓库！')
            this.notHave = true;
          }

        })
      },
      setEnum(fname,val) {
//
//        val = JSON.parse(val).map(item=>item.code).join(',');
//        this[fname] = val;
//        this.$emit('setVo', this.field.name, val);
        val = val.replace('|', ',');
        this[fname] = val;
        this.$emit('setVo', this.field.name,val );
      },
    },
    watch: {
    },
    computed: {
    },
    props: ['field'],
    created() {
      this.getProductAttr();
    },
    mounted() {
    }
  };
</script>

<style scoped>
</style>
